/**
 @file ctc_parser_cli.c

 @author  Copyright (C) 2011 Centec Networks Inc.  All rights reserved.

 @date 2009-12-28

 @version v2.0

This file contains parser module cli command
*/

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "sal.h"
#include "ctc_cli.h"
#include "ctc_cli_common.h"
#include "ctc_debug.h"
#include "ctc_error.h"
#include "ctcs_api.h"



CTC_CLI(ctc_cli_asw_parser_l2_set_tpid,
        ctc_cli_asw_parser_l2_set_tpid_cmd,
        "parser l2 ethernet tpid (cvlan|svlan0|svlan1|svlan2|svlan3) TPID",
        CTC_CLI_PARSER_STR,
        CTC_CLI_L2_HDR_STR,
        "Ethernet l2",
        "Type ID",
        "Customer vlan",
        "Service vlan0",
        "Service vlan1",
        "Service vlan2",
        "Service vlan3",
        "Tpid value<0x0 - 0xFFFF>")
{
    uint16 value = 0;
    ctc_parser_l2_tpid_t tp = 0;
    int32 ret = 0;

    if (0 == sal_memcmp(argv[0], "cvlan", 5))
    {
        tp = CTC_PARSER_L2_TPID_CVLAN_TPID;
    }
    else if (0 == sal_memcmp(argv[0], "svlan0", 6))
    {
        tp = CTC_PARSER_L2_TPID_SVLAN_TPID_0;
    }
    else if (0 == sal_memcmp(argv[0], "svlan1", 6))
    {
        tp = CTC_PARSER_L2_TPID_SVLAN_TPID_1;
    }
    else if (0 == sal_memcmp(argv[0], "svlan2", 6))
    {
        tp = CTC_PARSER_L2_TPID_SVLAN_TPID_2;
    }
    else if (0 == sal_memcmp(argv[0], "svlan3", 6))
    {
        tp = CTC_PARSER_L2_TPID_SVLAN_TPID_3;
    }

    CTC_CLI_GET_UINT16_RANGE("tpid_value", value, argv[1], 0, CTC_MAX_UINT16_VALUE);

    ret = ctcs_parser_set_tpid(g_api_lchip, tp, value);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_parser_show_l2_tpid,
        ctc_cli_asw_parser_show_l2_tpid_cmd,
        "show parser l2 ethernet tpid (cvlan|svlan0|svlan1|svlan2|svlan3)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_PARSER_STR,
        CTC_CLI_L2_HDR_STR,
        "Ethernet l2",
        "Type ID",
        "Customer vlan",
        "Service vlan0",
        "Service vlan1",
        "Service vlan2",
        "Service vlan3")
{
    uint16 value = 0;
    ctc_parser_l2_tpid_t tp = 0;
    int32 ret = 0;

    ctc_cli_out("%-9s%s\n", "Type", "Value");
    ctc_cli_out("---------------\n");

    if (0 == sal_memcmp(argv[0], "cvlan", 5))
    {
        tp = CTC_PARSER_L2_TPID_CVLAN_TPID;
    }
    else if (0 == sal_memcmp(argv[0], "svlan0", 6))
    {
        tp = CTC_PARSER_L2_TPID_SVLAN_TPID_0;
    }
    else if (0 == sal_memcmp(argv[0], "svlan1", 6))
    {
        tp = CTC_PARSER_L2_TPID_SVLAN_TPID_1;
    }
    else if (0 == sal_memcmp(argv[0], "svlan2", 6))
    {
        tp = CTC_PARSER_L2_TPID_SVLAN_TPID_2;
    }
    else if (0 == sal_memcmp(argv[0], "svlan3", 6))
    {
        tp = CTC_PARSER_L2_TPID_SVLAN_TPID_3;
    }

    ret = ctcs_parser_get_tpid(g_api_lchip, tp, &value);
    if (ret < 0)
    {
        ctc_cli_out("%% %s \n", ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("%-9s0x%x\n", argv[0], value);

    return CLI_SUCCESS;
}

int32
ctc_asw_parser_cli_init(uint8 cli_tree_mode)
{
    install_element(cli_tree_mode, &ctc_cli_asw_parser_l2_set_tpid_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_parser_show_l2_tpid_cmd);

    return CLI_SUCCESS;
}
